<?php

declare (strict_types=1);


namespace App\Models\GameDB\Fantasy;

use App\Models\MainDB\Gift;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class GiftConfig extends Model
{
    protected $connection = 'mysql_game';
    protected $table = 'lottery_fantasy_gift_config';

    protected $fillable = [
        'id', 'money', 'gift_ids', 'is_open', 'admin_id',
    ];
    public $timestamps = false;

    public function getGiftIdsAttribute($gift_ids)
    {
        if (is_string($gift_ids)) {
            $gift_ids = explode(',', $gift_ids);
        }
        return $gift_ids;
    }

    public function setGiftIdsAttribute($gift_ids)
    {
        if (is_array($gift_ids)) {
            $gift_ids = implode(',', $gift_ids);
        }
        $this->attributes['gift_ids'] = $gift_ids;
    }

    public function admin()
    {
        return $this->hasOne(\App\Models\GameDB\Admin::class, 'auth_id', 'admin_id');
    }

}
